package org.leetcode.middle.leetcode17;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Solution2 {

    String[] array = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};

    List<String> res = new ArrayList<>();
    StringBuilder temp = new StringBuilder();

    public List<String> letterCombinations(String digits) {
        if (digits.length()==0){
            return res;
        }
        backtracking(digits,0);
        return res;
    }

    private void backtracking(String digits, int index) {
        if (index >= digits.length()) {
            res.add(new String(temp));
            return;
        }

        char strIndex = digits.charAt(index);

        String str = array[strIndex-'0'];

        for (int i = 0; i < str.length(); i++) {
            temp.append(str.charAt(i));

            backtracking(digits,index+1);

            temp.deleteCharAt(temp.length()-1);
        }

    }
}
